﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;

namespace UAC.Operation
{
    /// <summary>
    /// 顺序：DocumentDef -> OperationDef -> ControlCondition
    /// </summary>
    public class ControlCondition
    {
        private int id = -1;
        public int ID { get { return id; } set { id = value; } }
        public int DocumentDefID { get; set; }
        public string Description { get; set; }
        public OperationType OperationType { get; set; }
        /// <summary>
        /// OperationType为And/Or时有效
        /// </summary>
        public List<ControlCondition> ConditionList { get; set; }

        /// <summary>
        /// 操作者是：PeopleID
        /// 操作者是角色：TeamDefID
        /// 比较：Value1
        /// </summary>
        public ConditionValue Values1 { get; set; }
        /// <summary>
        /// 操作者是角色：TeamRoleDefID
        /// 比较：Value2
        /// </summary>
        public ConditionValue Values2 { get; set; }
        /// <summary>
        /// 比较：大小关系
        /// </summary>
        public ConditionValue Values3 { get; set; }
        /// <summary>
        /// 比较：Value1和Value2值的类型
        /// </summary>
        public ConditionValue Values4 { get; set; }
        public ConditionValue Values5 { get; set; }

        public ControlCondition() { }

        public override string ToString()
        {
            return string.Format("{0}-{1}", this.DocumentDefID, this.Description);
        }
    }

    public enum CompareType : int
    {
        /// <summary>
        /// 等于
        /// </summary>
        Equal = 0,
        /// <summary>
        /// 不等于
        /// </summary>
        Unequal = 1,
        /// <summary>
        /// 大于
        /// </summary>
        Greater = 2,
        /// <summary>
        /// 大于等于
        /// </summary>
        GreaterOrEqual = 3,
        /// <summary>
        /// 小于
        /// </summary>
        Less = 4,
        /// <summary>
        /// 小于等于
        /// </summary>
        LessOrEqual = 5
    }

    public class ConditionValue
    {
        public ValueType ValueType { get; set; }
        public object Value { get; set; }

        public static int GetType(ConditionValue condition)
        {
            if (condition == null)
                return 0;
            return (int)condition.ValueType;
        }

        public static string GetValue(ConditionValue condition)
        {
            if (condition == null || condition.Value == null)
                return "";
            return condition.Value.ToString();
        }
    }

    public enum ValueType : int
    {
        /// <summary>
        /// 任意的
        /// </summary>
        Arbitrary = 0,
        /// <summary>
        /// 文档变量
        /// </summary>
        DocDef = 1,
        /// <summary>
        /// 常量
        /// </summary>
        Constant = 2
    }

    public enum ParamType : int
    {
        String = 0,
        Number = 1,
        Date = 2
    }

    public enum OperationType : int
    {
        /// <summary>
        /// And
        /// </summary>
        And = 0,
        /// <summary>
        /// Or
        /// </summary>
        Or = 1,
        /// <summary>
        /// 操作者是角色
        /// </summary>
        Role = 2,
        /// <summary>
        /// 操作者是
        /// </summary>
        Person = 3,
        /// <summary>
        /// 比较
        /// </summary>
        Compare = 4
    }
}
